package com.fyzk.activity.zhifu.zc;

import android.content.Context;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.fyzk.bean.ZCGameQueueItem;
import com.tyjc.lottery.R;
import com.fyzk.utils.TextStyleUtil;

import java.util.ArrayList;
import java.util.List;

public class ZhiFu_ZC_Adapter extends BaseAdapter{
	
	protected Context context;
	protected List<ZCGameQueueItem> infors = new ArrayList<ZCGameQueueItem>();
	protected ZC_ZhiFu_OnClickBallListerner listener;
	
	public ZhiFu_ZC_Adapter(Context context, List<ZCGameQueueItem> infors){
		this.context = context;
		this.infors = infors;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return infors.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return infors.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ZCGameQueueItem info = infors.get(position);
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.adapter_zc_pay, null);
			holder.num_tv = (TextView) convertView.findViewById(R.id.zc_pay_item_num);
			holder.home_tv = (TextView) convertView.findViewById(R.id.zc_pay_item_home);
			holder.away_tv = (TextView) convertView.findViewById(R.id.zc_pay_item_away);
			holder.sheng_cb = (CheckBox) convertView.findViewById(R.id.zc_pay_item_sheng);
			holder.ping_cb = (CheckBox) convertView.findViewById(R.id.zc_pay_item_ping);
			holder.fu_cb = (CheckBox) convertView.findViewById(R.id.zc_pay_item_fu);

			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}

		holder.num_tv.setText(""+(position+1));
		holder.home_tv.setText(info.getHomeTeam());
		holder.away_tv.setText(info.getAwayTeam());

		holder.sheng_cb.setChecked(info.isSheng);
		holder.ping_cb.setChecked(info.isPing);
		holder.fu_cb.setChecked(info.isFu);

		holder.sheng_cb.setText("");
		holder.ping_cb.setText("");
		holder.fu_cb.setText("");

		SpannableString spanString = TextStyleUtil.fontSizeSpan(new SpannableString("3 "), 18);
		spanString = TextStyleUtil.styleSpan(spanString, Typeface.BOLD);
		holder.sheng_cb.append(spanString);
		spanString = TextStyleUtil.fontSizeSpan(new SpannableString(" ("+info.getVs_3()+")"), 12);
		holder.sheng_cb.append(spanString);

		spanString = TextStyleUtil.fontSizeSpan(new SpannableString("1 "), 18);
		spanString = TextStyleUtil.styleSpan(spanString, Typeface.BOLD);
		holder.ping_cb.append(spanString);
		spanString = TextStyleUtil.fontSizeSpan(new SpannableString(" ("+info.getVs_1()+")"), 12);
		holder.ping_cb.append(spanString);

		spanString = TextStyleUtil.fontSizeSpan(new SpannableString("0 "), 18);
		spanString = TextStyleUtil.styleSpan(spanString, Typeface.BOLD);
		holder.fu_cb.append(spanString);
		spanString = TextStyleUtil.fontSizeSpan(new SpannableString(" ("+info.getVs_0()+")"), 12);
		holder.fu_cb.append(spanString);

		holder.sheng_cb.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (listener != null) {
					info.isSheng = !info.isSheng;
					if (info.isSheng) {
						info.clickNum++;
					} else {
						info.clickNum--;
					}
					listener.onClickBall();
				}
			}
		});

		holder.ping_cb.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (listener != null) {
					info.isPing = !info.isPing;
					if (info.isPing) {
						info.clickNum++;
					} else {
						info.clickNum--;
					}
					listener.onClickBall();
				}
			}
		});

		holder.fu_cb.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (listener != null) {
					info.isFu = !info.isFu;
					if (info.isFu) {
						info.clickNum++;
					} else {
						info.clickNum--;
					}
					listener.onClickBall();
				}
			}
		});

//		if (position == jcInfors.size()) {
//			holder.bg_center.setVisibility(View.GONE);
//			holder.bg_top.setVisibility(View.GONE);
//		} else {
//			Globle.setHW(holder.bg_top, 1080, 11, context);
//			ZCGameQueueItem info = jcInfors.get(position);
//			holder.fangshi.setText("[" + ConstantsDJ.wcode(info.wcodeID) + "]");
//			holder.tv_betNum.setText(Html.fromHtml(info.showZhuMa));
//			holder.zhu.setText(info.zhuShu + "注,");
//			holder.money.setText("共 " + info.zhuShu * 2 + " 米");
//			holder.bg_center.setOnClickListener(new OnClickListener() {
//				@Override
//				public void onClick(View v) {
//					// TODO Auto-generated method stub
//					if (listener != null) {
//						listener.onClickChange(position);
//					}
//				}
//			});
//			holder.delete.setOnClickListener(new OnClickListener() {
//
//				@Override
//				public void onClick(View v) {
//					// TODO Auto-generated method stub
//					if (listener != null) {
//						listener.onClickDelete(position);
//					}
//				}
//			});
//		}
		
		
		
		return convertView;
	}
	
	public void setListener(ZC_ZhiFu_OnClickBallListerner listener) {
		this.listener = listener;
	}
	
	public void setList(List<ZCGameQueueItem> infors){
		this.infors = infors;
		this.notifyDataSetChanged();
	}

	protected class ViewHolder{
		TextView num_tv;
		TextView home_tv;
		TextView away_tv;
		CheckBox sheng_cb;
		CheckBox ping_cb;
		CheckBox fu_cb;
	}

	interface ZC_ZhiFu_OnClickBallListerner {
		void onClickBall();
	}
	
	
	
	
	
	
	
	
}
